import time

from selenium.webdriver.common.by import By

from common.untils import Lunta

class LunTaLgoin:
    url=""
    driver=""
    def __init__(self):
        self.url="http://127.0.0.1:9580/sign-in.html"
        self.driver=Lunta.driver
        self.driver.get(self.url)

    #成功登陆
    def LTLoginTest(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("zhangsan")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        time.sleep(2)
        #查找头像是否登陆成功
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar")
        #截屏登陆成功页面
        Lunta.getScreenShot()
        # self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        # self.driver.find_element(By.CSS_SELECTOR,"#index_user_logout").click()
        # Lunta.getScreenShot()

    #登陆失败
    def LTFailTest(self):
        #密码错误
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("12345")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(1)
        Lunta.getScreenShot()
        #检测是否出现密码错误弹窗
        self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")

        #清空内容
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        # 用户名错误
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhang")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(1)
        Lunta.getScreenShot()
        # 检测是否出现密码错误弹窗
        self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")

        # 清空内容
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()

        # 用户名为空
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("12345")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(1)
        Lunta.getScreenShot()
        # 检测是否出现用户名不能为空提示
        text=self.driver.find_element(By.CSS_SELECTOR, "#signInForm > div.mb-3 > div").text
        assert text=="用户名不能为空"

        # 清空内容
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()

        # 用户名为空
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhang")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(1)
        Lunta.getScreenShot()
        # 检测是否出现用户名不能为空提示
        text = self.driver.find_element(By.CSS_SELECTOR, "#signInForm > div.mb-2 > div > div").text
        assert text == "密码不能为空"



